//
//  UISwitchDemo.swift
//  firstProject
//
//  Created by 张彦辉 on 2017/4/4.
//  Copyright © 2017年 张彦辉. All rights reserved.
//

import UIKit

class UISwitchDemo: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.gray
        let mySwitch:UISwitch = UISwitch(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
        //设置滑块的颜色
        mySwitch.thumbTintColor = UIColor.red
        //设置开关开启的颜色
        mySwitch.onTintColor = UIColor.green
        //关闭开关的颜色
        mySwitch.tintColor = UIColor.blue
        mySwitch.addTarget(self, action: #selector(switchClick), for: .valueChanged)
        self.view.addSubview(mySwitch)
    }
    
    func switchClick(swi:UISwitch){
        if swi.isOn {
            self.view.backgroundColor = UIColor.black
        }else{
            self.view.backgroundColor = UIColor.gray
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
